package com.dysoft.flesh;

import com.dysoft.bones.DataManager;

/**
 * @author Sean Micklethwaite
 *         Aug 14, 2010 10:00:58 PM
 */
public class DeferredPassRenderer extends RendererDecorator implements Renderer {
	final RenderTarget target;

	public DeferredPassRenderer(RenderTarget target, RenderComponent stage, Renderer renderer) {
		super(stage, renderer);
		this.target = target;
	}

	public void render(RenderContext ctx) {
		ctx.pushRenderer(this);
		target.activate(ctx);
		try {
			super.render(ctx);
		} catch(DataManager.DataObject.NotPresentException e) {
			LOG.warn("Skipping render pass - " + e);
		} finally {
			target.deactivate(ctx);
			ctx.popRenderer();
		}
	}

	@Override
	public String toString() {
		return "[" + super.toString() + "] -> " + target;
	}

	public RenderTarget getTarget() {
		return target;
	}
}
